package org.dromara.business.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.business.domain.bo.ShoppingCartBo;
import org.dromara.business.domain.vo.ShoppingCartVo;
import org.dromara.business.service.ShoppingCartService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 购物车
 *
 * @author zlj
 * @date 2024-08-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/cart")
public class ShoppingCartController extends BaseController {

    private final ShoppingCartService shoppingCartService;

    /**
     * 查询购物车列表
     */
    @GetMapping("/list")
    public TableDataInfo<ShoppingCartVo> list(ShoppingCartBo bo, PageQuery pageQuery) {
        return shoppingCartService.queryPageList(bo, pageQuery);
    }


    /**
     * 新增购物车
     */
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ShoppingCartBo bo) {
        return toAjax(shoppingCartService.insertByBo(bo));
    }


    /**
     * 清空购物车
     */
    @DeleteMapping("/clear")
    public R<Void> clear() {

        return toAjax(shoppingCartService.clear());
    }


}
